﻿<%@ WebHandler Language="C#" Class="HandlerAccount" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using BLL;
using PaymentBLL;
using DataContext;
using Utils;

public class HandlerAccount : IHttpHandler, IReadOnlySessionState
{

    public void ProcessRequest(HttpContext context)
    {
        string type = context.Request.QueryString["t"] ?? string.Empty;

        switch (type)
        {
           
            case "GetListAccount":
                GetListAccount(context);
                break;            
        }
    }


    public void GetListAccount(HttpContext context)
    {
        CtrAccount ctr = new CtrAccount();
        int currentPage = Convert.ToInt32(context.Request.QueryString["currentPage"] ?? "1");
        int pageSize = Convert.ToInt32(context.Request.QueryString["pageSize"] ?? "10");
        string name = context.Request.QueryString["name"] ?? "";
        int id = Convert.ToInt32(context.Request.QueryString["id"] ?? "-1");
        int typeId = Convert.ToInt32(context.Request.QueryString["typeId"] ?? "-1");
        short status = Convert.ToInt16(context.Request.QueryString["status"] ?? "-1");
        int? total = 0;
        var lstAcc = ctr.SelectAccountBy(id, typeId, name, status, currentPage, pageSize, ref total);
        string function = HttpContext.Current.Request.Headers["Referer"].Substring(HttpContext.Current.Request.Headers["Referer"].LastIndexOf("/") + 1);
        int p = CtrAdmin.GetPermission(function);
        var obj = new
                      {
                          Items = lstAcc,
                          TotalRecord = total,
                          Permission = p
                      };
        string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
        context.Response.ContentType = "application/json";
        context.Response.Write(jsonString);
    }

       public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
